/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.wx.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.wx.entity.WxBusinessGroup;
import com.jeesite.modules.wx.service.WxBusinessGroupService;

/**
 * 商家和组的对应关系表Controller
 * @author wangjianxin
 * @version 2018-12-03
 */
@Controller
@RequestMapping(value = "${adminPath}/wx/wxBusinessGroup")
public class WxBusinessGroupController extends BaseController {

	@Autowired
	private WxBusinessGroupService wxBusinessGroupService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public WxBusinessGroup get(String id, boolean isNewRecord) {
		return wxBusinessGroupService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("wx:wxBusinessGroup:view")
	@RequestMapping(value = {"list", ""})
	public String list(WxBusinessGroup wxBusinessGroup, Model model) {
		model.addAttribute("wxBusinessGroup", wxBusinessGroup);
		return "modules/wx/wxBusinessGroupList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("wx:wxBusinessGroup:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<WxBusinessGroup> listData(WxBusinessGroup wxBusinessGroup, HttpServletRequest request, HttpServletResponse response) {
		Page<WxBusinessGroup> page = wxBusinessGroupService.findPage(new Page<WxBusinessGroup>(request, response), wxBusinessGroup); 
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("wx:wxBusinessGroup:view")
	@RequestMapping(value = "form")
	public String form(WxBusinessGroup wxBusinessGroup, Model model) {
		model.addAttribute("wxBusinessGroup", wxBusinessGroup);
		return "modules/wx/wxBusinessGroupForm";
	}

	/**
	 * 保存商家和组的对应关系表
	 */
	@RequiresPermissions("wx:wxBusinessGroup:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated WxBusinessGroup wxBusinessGroup) {
		wxBusinessGroupService.save(wxBusinessGroup);
		return renderResult(Global.TRUE, text("保存商家和组的对应关系表成功！"));
	}
	
	/**
	 * 删除商家和组的对应关系表
	 */
	@RequiresPermissions("wx:wxBusinessGroup:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(WxBusinessGroup wxBusinessGroup) {
		wxBusinessGroupService.delete(wxBusinessGroup);
		return renderResult(Global.TRUE, text("删除商家和组的对应关系表成功！"));
	}
	
}